// 认证相关API服务

import { http } from './http';
import type { LoginRequest, LoginApiResponse, RegisterRequest, ApiResponse } from '../types/auth';

// 认证API类
class AuthApi {
  // 登录
  async login(data: LoginRequest): Promise<LoginApiResponse> {
    return http.post<LoginApiResponse['data']>('/auth/login', data);
  }

  // 注册
  async register(data: Omit<RegisterRequest, 'confirmPassword'>): Promise<ApiResponse> {
    return http.post('/auth/register', data);
  }

  // 登出
  async logout(): Promise<void> {
    // 清除本地存储的token
    localStorage.removeItem('accessToken');
    localStorage.removeItem('userInfo');
  }

  // 获取当前用户信息
  async getCurrentUser() {
    return http.get('/auth/me');
  }

  // 刷新token
  async refreshToken() {
    return http.post('/auth/refresh');
  }
}

// 导出认证API实例
export const authApi = new AuthApi();

// 导出默认实例
export default authApi;